package me.zhengjie.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.dao.*;
import me.zhengjie.server.ContainerService;
import me.zhengjie.server.StoreLocalService;
import me.zhengjie.server.WcsToSendWmsService;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.Result;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequiredArgsConstructor
@Api(tags = "WcsToSendWmsController")
@RequestMapping("/wms")
public class WcsToSendWmsController {
    private final WcsToSendWmsService wcsToSendWmsService;
    private final StoreLocalService storeLocalService;
    private final ContainerService containerService;

    @PostMapping(value = "/emptyContainer")
    @Log("空箱申请起点出库")
    @ApiOperation("空箱申请起点出库")
    public Result<EmptyContainerDao> emptyContainer(String station){
        EmptyContainerDao emptyContainerDao = wcsToSendWmsService.emptyContainer(station);
        return Result.ok(emptyContainerDao);
    }


    @PostMapping(value = "/circleLibrary/palletCode")
    @Log("一楼回库通过储位编码获取载具编码")
    @ApiOperation("一楼回库通过储位编码获取载具编码")
    public Result<PalletCodeDao> palletCode(String palletCode){
        return Result.ok(wcsToSendWmsService.palletCode(palletCode));
    }
    @PostMapping(value = "/Code")
    @Log("二楼出库整板或分拣回报WCS")
    @ApiOperation("二楼出库整板或分拣回报WCS")
    public Result requiteWcs(String containerCode,String type){

        return Result.ok();
    }


    @PostMapping(value = "/toWms")
    @Log("WCS取货放货成功反馈")
    @ApiOperation("WCS取货放货成功反馈")
    public Result<Object> WcsToWms(String containerCode,String storageCode,int type,int taskType,int bound_type){
        if(bound_type==2&&type==1&&taskType==1){
            //找到储位解锁储位并修改状态
            StoreLocalDao storeLocalDao = storeLocalService.getOne(new LambdaQueryWrapper<StoreLocalDao>().eq(StoreLocalDao::getId, storageCode)).setIsLock(0).setStatus(0);
            storeLocalService.updateById(storeLocalDao);
            //找到载具修改载具位置
            ContainerDao containerDao = containerService.getOne(new LambdaQueryWrapper<ContainerDao>().eq(ContainerDao::getId, containerCode)).setLocal("库外");
            boolean b = containerService.updateById(containerDao);
            return Result.ok(b);
        }else {
            return Result.fail();
        }
    }



}
